package com.qf.controller;

import com.qf.pojo.Profile;
import com.qf.service.ProfileService;
import com.qf.service.ProfileServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author fy
 * @version V1.0
 * @Project day41
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/5/27 13:46
 */
@WebServlet("/MyProfile")
public class ProfileController extends BaseServlet{


    /**
     * 跳转到档案详情
     * @param request
     * @param response
     * @return
     */
    public String detail(HttpServletRequest request,HttpServletResponse response){
        //1：接受传入的参数，档案id
        String id = request.getParameter("id");

        //2:根据商品id查询商品详细信息
        ProfileService profileService = new ProfileServiceImpl();
        Profile profile = profileService.findProfileById(Integer.parseInt(id));
        //3:将查询到的商品数据放入request请求域对象中，带到页面中展示
        request.setAttribute("profile", profile);//"profile"是detail页面中的${profile}

        //4:请求转发到商品详情页面
        return "forward:/detail.jsp";
    }
    /**
     * 查询档案列表展示
     * @return
     */
    public String list(HttpServletRequest request,HttpServletResponse response) throws Exception{
        //1:调用service查询所有商品数据
        ProfileService profileService = new ProfileServiceImpl();
        List<Profile> list = profileService.findProfileAll();

        //2：将商品数据存入request域对象中
        request.setAttribute("profileList", list);
        return "forward:/list.jsp";


    }


}
